package edu.fzu.crud.controller;

import edu.fzu.crud.common.Result;
import edu.fzu.crud.service.OssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author JohnCarraway
 * @create 2021-01-03 14:57
 */
@RestController
public class OssController {

    @Autowired
    private OssService ossService;

    @RequestMapping(value = "/ossservice/uploadAvatar", method = RequestMethod.POST)
    public Result upLoadAvatarToOss(MultipartFile file){
        if (file == null){
            System.out.println("没有接收到前端传来的文件");
        } else{
            System.out.println("接收到文件了");
        }
        String url = ossService.uploadAvatar(file);
        return Result.success().add("url", url);
    }


}
